<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
import VueRouter from "vue-router";

export default {
  name: "app",
  data() {
    return {};
  },
  beforeMount() {},
  beforeCreate() {},
  created() {
    // this.islogin();
  },
  mounted: function() {
    this.islogin();
  },
  methods: {
    islogin() {
      // 调用axios请求数据,axios的成功的回调要是.then这个方法来调用
      // 判断用户是否登录
      this.$axios({
        method: "GET",
        url: "/admin/account/islogin",
        // 由于在8080端口下去请求8899端口，涉及到跨域
        withCredentials: true
      }).then(res => {
        // sessionStorage.setItem("islogin", res.data.code);
        if (res.data.code == "nologin") {
          this.$router.push("/login");
        }
      });
    }
  },
  
  watch: {
    $route: {
      handler: function(val, oldVal) {
        this.islogin();
      },
      // 深度观察监听
      deep: true
    },
    
  }
};
</script>

<style>
* {
  padding: 0;
  margin: 0;
}
</style>
